package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Game;
import com.ruoyi.system.service.IGameService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 游戏信息模块Controller
 * 
 * @author ruoyi
 * @date 2024-12-11
 */
@RestController
@RequestMapping("/system/game")
public class GameController extends BaseController
{
    @Autowired
    private IGameService gameService;

    /**
     * 查询游戏信息模块列表
     */
    @PreAuthorize("@ss.hasPermi('system:game:list')")
    @GetMapping("/list")
    public TableDataInfo list(Game game)
    {
        startPage();
        List<Game> list = gameService.selectGameList(game);
        return getDataTable(list);
    }

    /**
     * 导出游戏信息模块列表
     */
    @PreAuthorize("@ss.hasPermi('system:game:export')")
    @Log(title = "游戏信息模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Game game)
    {
        List<Game> list = gameService.selectGameList(game);
        ExcelUtil<Game> util = new ExcelUtil<Game>(Game.class);
        util.exportExcel(response, list, "游戏信息模块数据");
    }

    /**
     * 获取游戏信息模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:game:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gameService.selectGameById(id));
    }

    /**
     * 新增游戏信息模块
     */
    @PreAuthorize("@ss.hasPermi('system:game:add')")
    @Log(title = "游戏信息模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Game game)
    {
        return toAjax(gameService.insertGame(game));
    }

    /**
     * 修改游戏信息模块
     */
    @PreAuthorize("@ss.hasPermi('system:game:edit')")
    @Log(title = "游戏信息模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Game game)
    {
        return toAjax(gameService.updateGame(game));
    }

    /**
     * 删除游戏信息模块
     */
    @PreAuthorize("@ss.hasPermi('system:game:remove')")
    @Log(title = "游戏信息模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gameService.deleteGameByIds(ids));
    }
}
